
/***************************************************************************
 *   Copyright (C) 2009 by Bernhard Neuhofer   *
 *   mail@bneu.at   *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/
#ifndef __ABSTRACTLP_H
#define __ABSTRACTLP_H

class AbstractLp;

#include "message.h"
#include "modelentity.h"
#include "abstractAdapter.h"
#include "gvtStats.h"
#include "smOutput.h"
#include "messageHandler.h"
#include "../tools/log.h"
using namespace std;

#include <iostream>
/** 
* @brief The abstract root of all LPs
*/
class AbstractLp
{
	private:
//Positive, unique LP identification number
		unsigned int _id;

//Contains the reference to the associated message handler.
MessageHandler* _assocMh;


//Contains the reference to the associated model entity.

		ModelEntity * _assocMe;

//Contains the reference to the associated adapter
AbstractAdapter* _assocAd;


//Contains the reference to the SMs Output collector
SmOutput* _smOutput;
		

//Contains the reference to the SMs GvtStats object
GvtStats* _gvtStats;



//Local GvtStats snapshot for the current step
GvtStats* _stepStats;


	public:

		/**
		 * Subclasses use this constructor to initialise the attributes common to all LPs
		 * @param id positive, unique LP identification number
		 */
		AbstractLp ( unsigned int id ) : _id ( id ) {
		FILE_LOG(logDEBUG)<<"constructor abstractlp init stepstats";
		_stepStats=new GvtStats();

		
		}

		/**
		 * used by the submodel manager to make a specific LP execute one step
		 */
		virtual void doStep() =0;


		/**
		 * Sends a message to a given LP by invoking the <code>receiveMessage</code> method of the associated message handler of the receiver
		 * @param message The message to send
		 */
		virtual void sendMessage ( Message *message ) =0;


		/**
		 * Used to aquire the LVT of the LP
		 * @return The local virtual time of the LP
		 */
		virtual double getLvt() =0;

		/**
		 * Returns the Id of the LP
		 * @return int
		 */
		virtual unsigned int getId();

		/**
		 * Sets the associated adapter.
		 * @param assocAd The associated adapter
		 */
		virtual void setAssocAd ( AbstractAdapter* assocAd );

		/**
		 * Sets the associated model entity
		 * @param assocMe The associated model entity
		 */
		virtual void setAssocMe ( ModelEntity *assocMe );
		/**
		 * Sets the GvtStats
		 * @param gvtStats The GvtStats object
		 */
		virtual void setGvtStats ( GvtStats* gvtStats );

		/**
		 * Sets the associated message handler
		 * @param assocMh The associated message Handler
		 */
		virtual void setAssocMh ( MessageHandler* assocMh );

		/**
		 * Returns the associated adapter
		 * @return AbstractAdapter
		 */
		virtual AbstractAdapter* getAssocAd();
		/**
		 * Returns the associated model entity
		 * @return ModelEntity
		 */
		virtual ModelEntity * getAssocMe();
		/**
		 * Returns the associated message handler
		 * @return MessageHandler
		 */
		virtual MessageHandler* getAssocMh();
		/**
		 * Returns the SmOutput Object
		 * @return SmOutput
		 */
		virtual SmOutput* getSmOutput();

		/**
		 * Returns the GvtStats object
		 * @return GvtStats
		 */
		virtual GvtStats* getGvtStats();

		/**
		 * Get the current stepStats
		 * @return GvtStats
		 */
		virtual GvtStats* getStepStats();

		/**
		 * Set the smOutput.
		 * @param smOutput Set the smOutput object
		 */
		virtual void setSmOutput ( SmOutput* smOutput );

		/**
		 * Set the stepStats.
		 * @param stepStats Set the stepStat object
		 */
		virtual void setStepStats ( GvtStats* stepStats );
};

#endif //ABSTRACTLP
